﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace He.Framework.AttributeMapping
{
    public static class AttributeMappingExtend
    {
        public static string GetMappingName(this MemberInfo member)
        {
            if (member.IsDefined(typeof(AbstractMappingAttribute), true))
            {
                AbstractMappingAttribute attribute = member.GetCustomAttribute<AbstractMappingAttribute>();
                return attribute.GetRealName();
            }
            else
            {
                return member.Name;
            }
        }
        public static List<PropertyInfo> GetPropertiesWithoutKey(this Type type)
        {
            return type.GetProperties().Where(p => !p.IsDefined(typeof(KeyAttribute), true)).ToList();
        }
        //public static string GetPropertyMappingName(this PropertyInfo prop)
        //{
        //    if (prop.IsDefined(typeof(TableAttribute), true))
        //    {
        //        ColumnAttribute attribute = prop.GetCustomAttribute<ColumnAttribute>();
        //        return attribute.GetRealName();
        //    }
        //    else
        //    {
        //        return prop.Name;
        //    }
        //}

    }
}
